package com.foolishbird.sdk.ui.fragment;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.foolishbird.sdk.core.HttpEngineApi;
import com.foolishbird.sdk.params.FloatKefuResponseParams;
import com.foolishbird.sdk.params.ResponseParams;
import com.foolishbird.sdk.params.bean.FloatKefu;
import com.foolishbird.sdk.params.bean.FloatNoticeInfo;
import com.foolishbird.sdk.params.bean.FloatUserInfo;
import com.foolishbird.sdk.params.bean.State;
import com.foolishbird.sdk.ui.assist.OnFinishActivityListener;
import com.foolishbird.sdk.utils.MyFragmentManger;
import com.foolishbird.sdk.utils.ResUtils;
import com.foolishbird.sdk.utils.WL;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;


public class FloatNoticeInfoFragment extends BaseHttpFragment implements View.OnClickListener {


//    private LinearLayout phoneLayout,realnameLayout,versionLayout,pwdLayout;
    private TextView titleTxt;
    private ImageView backView;
    TextView noticeTitleText;
    TextView timeText;
    TextView tagText1;
    TextView tagText2;
    TextView tagText3;
    WebView conentView;

    public static final FloatNoticeInfoFragment newInstance(Bundle bundle) {
        FloatNoticeInfoFragment fragment = new FloatNoticeInfoFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        int resource = ResUtils.getLayoutIdentifier(getActivity(), "fb_fragment_float_noticeinfo");
        View contentView =inflater.inflate(resource,null);
        titleTxt = contentView.findViewById(getViewIdentifier("fb_fragment_float_title"));
        titleTxt.setText(getArguments().getString("title"));
        backView = contentView.findViewById(getViewIdentifier("fb_fragment_login_back"));
        backView.setOnClickListener(this);
        noticeTitleText = contentView.findViewById(getViewIdentifier("float_notice_title"));
        timeText = contentView.findViewById(getViewIdentifier("float_notice_time"));
        tagText1 = contentView.findViewById(getViewIdentifier("float_notice_tag1"));
        tagText2 = contentView.findViewById(getViewIdentifier("float_notice_tag2"));
        tagText3 = contentView.findViewById(getViewIdentifier("float_notice_tag3"));
        conentView = contentView.findViewById(getViewIdentifier("gamenotice_content"));
        conentView.setBackgroundColor(0);
        conentView.getBackground().setAlpha(0);
        FloatNoticeInfo info = (FloatNoticeInfo)getArguments().getSerializable("notice");
        setInfo(info);

        return contentView;

    }
    SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd");
    private void setInfo(FloatNoticeInfo info) {
        conentView.loadDataWithBaseURL(null, info.getContent(), "text/html", "utf-8", null);
        noticeTitleText.setText(info.getTitle());
        try {
            timeText.setText(sdf1.format(sdf1.parse(info.getCreatedAt())));
        } catch (Exception e) {
            timeText.setText(info.getCreatedAt());
        }
        String tags = info.getTags();
        if (TextUtils.isEmpty(tags)) {
            tagText1.setVisibility(View.GONE);
            tagText2.setVisibility(View.GONE);
            tagText3.setVisibility(View.GONE);
        } else if (!tags.contains(",")) {
            tagText1.setVisibility(View.VISIBLE);
            tagText2.setVisibility(View.GONE);
            tagText3.setVisibility(View.GONE);
            tagText1.setText(tags);
        } else {
            String[] tagArray = tags.split(",");
            if (tagArray.length == 2) {
                tagText1.setVisibility(View.VISIBLE);
                tagText2.setVisibility(View.VISIBLE);
                tagText3.setVisibility(View.GONE);
                tagText1.setText(tagArray[0]);
                tagText2.setText(tagArray[1]);
            } else {
                tagText1.setVisibility(View.VISIBLE);
                tagText2.setVisibility(View.VISIBLE);
                tagText3.setVisibility(View.VISIBLE);
                tagText1.setText(tagArray[0]);
                tagText2.setText(tagArray[1]);
                tagText3.setText(tagArray[3]);
            }
        }
    }



    @Override
    public void onClick(View view) {
        if(view == backView){
//            if(userInfo!=null&&!TextUtils.isEmpty(userInfo.getId_number())){
//
//            }
            MyFragmentManger.getInstance().goBack(this);
        }
    }


}
